<?php

namespace App\Console\Commands;

use App\Models\StoreCoupon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class UpdateDiscountCoupon extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'UpdateDiscountCoupon';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $data = StoreCoupon::where('status', 1)->where('is_del', 0)->get()->toArray();
        foreach ($data as $k => $v) {
            $day = $v['coupon_time'];
            $now = $v['add_time'];
            if (strtotime("$now" . " +$day day") < time()) {
                StoreCoupon::where('id', $v['id'])->update(['is_del' => 1]);
            }
        }

    }
}
